/*     */ package com.qmsk.business.member.memberCouponBill.controller;
/*     */ 
/*     */ import com.qmsk.business.manage.cust.dao.CustDAO;
/*     */ import com.qmsk.business.member.memberCouponBill.dao.MemberCouponBillDao;
/*     */ import com.qmsk.business.member.memberCouponDetail.dao.MemberCouponDetailDao;
/*     */ import com.qmsk.business.member.memberCouponRule.dao.MemberCouponRuleDao;
/*     */ import com.utils.basic.CDateTimeComm;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.Date;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"memberConpBill"})
/*     */ public class MemberCouponBillController
/*     */ {
/*  32 */   private static final Logger logger = Logger.getLogger(MemberCouponBillController.class);
/*     */ 
/*     */   @Autowired
/*     */   private MemberCouponDetailDao memberCouponDetailDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCouponBillDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCouponRuleDao memberCoupRuleDao;
/*     */ 
/*     */   @Autowired
/*     */   private CustDAO custDao;
/*     */ 
/*     */   @RequestMapping(value={"insert/coupBill/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void getIntOfMemberId(@PathVariable("shopId") Long shopId, HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*  59 */     String openId = RequestUtils.getString(request, "openId");
/*     */     try {
/*  61 */       int nResult = 0;
/*  62 */       Long memberId = null;
/*  63 */       if ((shopId != null) && (StringUtils.isNotEmpty(openId))) {
/*  64 */         memberId = this.custDao.getOpenIdOfMemberId(openId);
/*  65 */         if ((memberId.longValue() > 0L) && (shopId != null) && (shopId.longValue() > 0L)) {
/*  66 */           Date crTime = this.dao.getCrTimeOfIsAttention(memberId, 
/*  67 */             shopId);
/*  68 */           boolean isInSevenDay = false;
/*  69 */           if (crTime != null) {
/*  70 */             crTime = CDateTimeComm.getAddDate(crTime, 7);
/*  71 */             Long bigTime = Long.valueOf(crTime.getTime());
/*     */ 
/*  73 */             Long endTime = Long.valueOf(new Date().getTime());
/*  74 */             if (bigTime.longValue() > Long.valueOf(endTime.longValue()).longValue()) {
/*  75 */               isInSevenDay = true;
/*     */             }
/*     */           }
/*     */ 
/*  79 */           if ((crTime == null) || ((crTime != null) && (!(isInSevenDay)))) {
/*  80 */             GsonHeadOneRow g = this.memberCoupRuleDao
/*  81 */               .getCouponRuleOneRowInfo(shopId);
/*  82 */             if ((g != null) && (g.isExistsData())) {
/*  83 */               String[] billHeads = { "MemberID", 
/*  84 */                 "RuleID", "ShopID", "CouponNo", 
/*  85 */                 "FaceValue", "crFTime", "crFMan", "Status", 
/*  86 */                 "BillFrom", "CouponCount", "IsAttention" };
/*  87 */               String ruleFlag = (String)g
/*  88 */                 .getValueOfName("RuleFlag");
/*  89 */               Long ruleId = ObjectComm.objectToLong(g
/*  90 */                 .getValueOfName("RuleID"));
/*  91 */               Double faceValue = ObjectComm.objectToDouble(g
/*  92 */                 .getValueOfName("FaceValue"));
/*  93 */               String couponNo = null;
/*  94 */               if (StringUtils.isNotEmpty(ruleFlag)) {
/*  95 */                 couponNo = this.memberCoupRuleDao
/*  96 */                   .getConponMaxNo(ruleFlag);
/*     */               }
/*  98 */               Object[] billDatas = { memberId, 
/*  99 */                 ruleId, shopId, couponNo, faceValue, 
/* 100 */                 new Date(), "wx", Integer.valueOf(0), "主动获取", Integer.valueOf(1), Integer.valueOf(1) };
/*     */ 
/* 102 */               GsonHeadOneRow r = new GsonHeadOneRow(billHeads, 
/* 103 */                 billDatas);
/* 104 */               nResult = this.dao.insertGsonHeadOneRow(r);
/* 105 */               Long billId = this.dao.getLastId();
/* 106 */               if (nResult > 0) {
/* 107 */                 g.delHead(new String[] { "RuleID", "RuleFlag" });
/* 108 */                 String[] dtHeads = { "MemberID", 
/* 109 */                   "CouponNo", "GrantDate", "Status", 
/* 110 */                   "GetMode", "CouponCount", "billId" };
/* 111 */                 Object[] dtDatas = { memberId, 
/* 112 */                   couponNo, new Date(), Integer.valueOf(0), "主动获取", Integer.valueOf(1), billId };
/* 113 */                 g.autoAddHeadData(dtHeads, dtDatas);
/* 114 */                 nResult = this.memberCouponDetailDao
/* 115 */                   .insertGsonHeadOneRow(g);
/* 116 */                 if (nResult > 0)
/* 117 */                   nResult = this.memberCoupRuleDao.updateUsed(ruleId);
/*     */               }
/*     */             }
/*     */             else
/*     */             {
/* 122 */               ResponseUtils.setErrorMsgResponse("该店的优惠券没有相应设置", 
/* 123 */                 response);
/* 124 */               return;
/*     */             }
/*     */           } else {
/* 127 */             ResponseUtils.setErrorMsgResponse("该店优惠券7天内只能获取一次", 
/* 128 */               response);
/* 129 */             return;
/*     */           }
/*     */         } else {
/* 132 */           ResponseUtils.setErrorMsgResponse("您还不是会员", response);
/* 133 */           return;
/*     */         }
/*     */       } else {
/* 136 */         ResponseUtils.setErrorMsgResponse("获取openId失败", response);
/* 137 */         return;
/*     */       }
/*     */ 
/* 140 */       if (nResult > 0)
/* 141 */         DbConnection.commit();
/*     */       else {
/* 143 */         DbConnection.rollback();
/*     */       }
/*     */ 
/* 146 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 147 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 148 */         response);
/*     */     } catch (Exception e) {
/* 150 */       logger.error(e);
/* 151 */       DbConnection.rollback();
/* 152 */       ResponseUtils.setErrorMsgResponse(
/* 153 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 154 */         e.getMessage(), response); }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"insert/getCoupon"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void getCoupon(HttpServletRequest request, HttpServletResponse response) {
/* 159 */     String openId = RequestUtils.getString(request, "openId");
/* 160 */     Long id = RequestUtils.getLong(request, "id");
/*     */     try {
/* 162 */       int nResult = 0;
/* 163 */       Long memberId = null;
/* 164 */       if ((id != null) && (StringUtils.isNotEmpty(openId))) {
/* 165 */         memberId = this.custDao.getOpenIdOfMemberId(openId);
/* 166 */         if ((memberId.longValue() > 0L) && (id != null) && (id.longValue() > 0L))
/*     */         {
/* 181 */           GsonHeadOneRow g = this.memberCoupRuleDao
/* 182 */             .getCouponRuleOneRowById(id);
/* 183 */           if ((g != null) && (g.isExistsData())) {
/* 184 */             Integer totalNum = ObjectComm.objectToInteger(g.getValueOfName("totalNum"));
/* 185 */             Integer usedNum = ObjectComm.objectToInteger(g.getValueOfName("usedNum"));
/* 186 */             if (usedNum.intValue() >= totalNum.intValue()) {
/* 187 */               ResponseUtils.setErrorMsgResponse("该优惠劵已发送完毕", response);
/* 188 */               return;
/*     */             }
/* 190 */             Long ruleId = ObjectComm.objectToLong(g
/* 191 */               .getValueOfName("RuleID"));
/* 192 */             if (this.dao.isExistByMemberIdAndRuleId(memberId, ruleId) > 0) {
/* 193 */               ResponseUtils.setErrorMsgResponse("您已领取该优惠券", response);
/* 194 */               return;
/*     */             }
/*     */ 
/* 197 */             String[] billHeads = { "MemberID", 
/* 198 */               "RuleID", "ShopID", "CouponNo", 
/* 199 */               "FaceValue", "crFTime", "crFMan", "Status", 
/* 200 */               "BillFrom", "CouponCount", "IsAttention" };
/* 201 */             String ruleFlag = (String)g
/* 202 */               .getValueOfName("RuleFlag");
/*     */ 
/* 204 */             Long shopId = ObjectComm.objectToLong(g.getValueOfName("ShopID"));
/* 205 */             Double faceValue = ObjectComm.objectToDouble(g
/* 206 */               .getValueOfName("FaceValue"));
/* 207 */             String couponNo = null;
/* 208 */             if (StringUtils.isNotEmpty(ruleFlag)) {
/* 209 */               couponNo = this.memberCoupRuleDao
/* 210 */                 .getConponMaxNo(ruleFlag);
/*     */             }
/* 212 */             Object[] billDatas = { memberId, 
/* 213 */               ruleId, shopId, couponNo, faceValue, 
/* 214 */               new Date(), "wx", Integer.valueOf(0), "主动获取", Integer.valueOf(1), Integer.valueOf(1) };
/*     */ 
/* 216 */             GsonHeadOneRow r = new GsonHeadOneRow(billHeads, 
/* 217 */               billDatas);
/* 218 */             nResult = this.dao.insertGsonHeadOneRow(r);
/* 219 */             Long billId = this.dao.getLastId();
/* 220 */             if (nResult > 0) {
/* 221 */               g.delHead(new String[] { "RuleID", "RuleFlag", "totalNum", "usedNum" });
/* 222 */               String[] dtHeads = { "MemberID", 
/* 223 */                 "CouponNo", "GrantDate", "Status", 
/* 224 */                 "GetMode", "CouponCount", "billId" };
/* 225 */               Object[] dtDatas = { memberId, 
/* 226 */                 couponNo, new Date(), Integer.valueOf(0), "主动获取", Integer.valueOf(1), billId };
/* 227 */               g.autoAddHeadData(dtHeads, dtDatas);
/* 228 */               nResult = this.memberCouponDetailDao
/* 229 */                 .insertGsonHeadOneRow(g);
/* 230 */               if (nResult > 0)
/* 231 */                 nResult = this.memberCoupRuleDao.updateUsed(id);
/*     */             }
/*     */           }
/*     */           else
/*     */           {
/* 236 */             ResponseUtils.setErrorMsgResponse("该优惠券不存在", 
/* 237 */               response);
/* 238 */             return;
/*     */           }
/*     */ 
/*     */         }
/*     */         else
/*     */         {
/* 246 */           ResponseUtils.setErrorMsgResponse("您还不是会员", response);
/* 247 */           return;
/*     */         }
/*     */       } else {
/* 250 */         ResponseUtils.setErrorMsgResponse("获取openId失败", response);
/* 251 */         return;
/*     */       }
/*     */ 
/* 254 */       if (nResult > 0)
/* 255 */         DbConnection.commit();
/*     */       else {
/* 257 */         DbConnection.rollback();
/*     */       }
/*     */ 
/* 260 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 261 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 262 */         response);
/*     */     } catch (Exception e) {
/* 264 */       logger.error(e);
/* 265 */       DbConnection.rollback();
/* 266 */       ResponseUtils.setErrorMsgResponse(
/* 267 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 268 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.memberCouponBill.controller.MemberCouponBillController
 * JD-Core Version:    0.5.3
 */